<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="com.sks.bean.privilege.SystemPrivilege"%>
<%@page import="java.util.Set"%>
<%@ include file="../share/taglib.jsp"%>
<%@ include file="/sks/cms/page/share/validate.inc"%>
<html>
<head>
<title><bean:message key="display.${privilegeGroupForm.method eq 'edit' ? 'edit' : 'add' }"/>权限组</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="/css/vip.css" type="text/css">
<script language="JavaScript">
function bodyOnLoad() {
	tt.vf.req.add('name');
	<%
	Set<SystemPrivilege> ps = (Set<SystemPrivilege>) request.getAttribute("selectprivileges");
	if (null != ps) {
		for (SystemPrivilege sp : ps) {
		%>
	document.getElementById('p_<%=sp.getId().getModule()%>_<%=sp.getId().getPrivilege()%>').checked = true;
		<%
		}
	}
	%>

	var ps = document.getElementsByName('privileges');
	for (var i = 0; i < ps.length; i++) {
		if (ps[i].checked) {
			checkEdit(ps[i]);
		}
	}
}
function selectAllPrivilege() {
	var selectAll = document.getElementById('selectAll');
	var ps = document.getElementsByName('privileges');
	if (selectAll != null && ps != null) {
		for (var i = 0; i < ps.length; i++) {
			ps[i].checked = selectAll.checked;
			ps[i].onclick();
		}
	}
}
function checkEdit(obj) {
	var idStr = obj.id + '';
	var _index = idStr.lastIndexOf("_");
	if (_index != -1) {
		var pp = idStr.substring(_index+1, idStr.length);
		if (pp == 'update') {
			var viewId = idStr.substring(0, _index) + '_view';
			var view = document.getElementById(viewId);
			if (null != view) {
				if (obj.checked) {
					view.checked = true;
					view.disabled = "disabled";
				} else {
					view.disabled = "";
				}
			}
		}
	}
}
function submitForm() {
	if (!tt.validate()) {
		return false;
	}
	var ps = document.getElementsByName('privileges');
	if (ps != null) {
		for (var i = 0; i < ps.length; i++) {
			ps[i].disabled = '';
		}
	}
	return true;
}
</script>
</head>
<body onload="bodyOnLoad();" bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	<html:form action="/cms/privilege/privilegegroup/manage.do" method="post" onsubmit="return submitForm();">
		<input type="hidden" name="method" value="${privilegeGroupForm.method}">
		<html:hidden property="groupid" />
		<table width="90%" border="0" cellspacing="2" cellpadding="3" align="center">
			<tr bgcolor="#ffbe26">
				<td colspan="2">
					<strong><font color="#000000"><bean:message key="display.${privilegeGroupForm.method eq 'edit' ? 'edit' : 'add' }"/>权限组：</font></strong>
				</td>
			</tr>
			<tr bgcolor="f5f5f5">
				<td width="15%"><div align="right">权限组名称：</div></td>
				<td width="85%"><html:text property="name" size="50" /></td>
			</tr>
			
			<tr bgcolor="#ffbe26">
				<td align="center">模块</td>
				<td>
					<table width="100%" border="0" cellspacing="2" cellpadding="3">
						<tr>
							<td width="80%">权限</td>
							<td width="20%" align="center"><input type="checkbox" id="selectAll" onclick="selectAllPrivilege();"/></td>
						</tr>
					</table>
				</td>
			</tr>
			
			<tr bgcolor="f5f5f5">
				<td align="center">业务管理权限</td>
				<td>
					<table width="100%">
					<c:forEach items="${hb}" var="p" varStatus="statu">
						<tr onmouseover="this.style.background = '#ffbe26';" onmouseout="this.style.background = '';">
							<td width="80%">${p.name}</td>
							<td width="20%" align="center">
							<input type="checkbox" id="p_${p.id.module}_${p.id.privilege}" name="privileges" onclick="checkEdit(this);" value="${p.id.module},${p.id.privilege}">
							</td>
						</tr>
					</c:forEach>
					</table>
				</td>
			</tr>
			
			<tr bgcolor="f5f5f5">
				<td align="center">内部管理权限</td>
				<td>
					<table width="100%">
					<c:forEach items="${internal}" var="p" varStatus="statu">
						<tr onmouseover="this.style.background = '#ffbe26';" onmouseout="this.style.background = '';">
							<td width="80%">${p.name}</td>
							<td width="20%" align="center">
							<input type="checkbox" id="p_${p.id.module}_${p.id.privilege}" name="privileges" onclick="checkEdit(this);" value="${p.id.module},${p.id.privilege}">
							</td>
						</tr>
					</c:forEach>
					</table>
				</td>
			</tr>
			
			<tr bgcolor="f5f5f5">
				<td align="center">资讯管理权限</td>
				<td>
					<table width="100%">
					<c:forEach items="${fn}" var="p" varStatus="statu">
						<tr onmouseover="this.style.background = '#ffbe26';" onmouseout="this.style.background = '';">
							<td width="80%">${p.name}</td>
							<td width="20%" align="center">
							<input type="checkbox" id="p_${p.id.module}_${p.id.privilege}" name="privileges" onclick="checkEdit(this);" value="${p.id.module},${p.id.privilege}">
							</td>
						</tr>
					</c:forEach>
					</table>
				</td>
			</tr>
			
			<tr bgcolor="f5f5f5">
				<td colspan="3">
					<div align="center">
						<input type="submit" name="SYS_SET" value="<bean:message key="display.save"/>" class="frm_btn">
					</div>
				</td>
			</tr>
		</table>
	</html:form>
	<br>
</body>
</html>